package com.zh.seckill.controller;

import com.zh.seckill.pojo.User;
import com.zh.seckill.service.GoodsService;
import com.zh.seckill.service.UserService;
import com.zh.seckill.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 商品
 *
 * @Author: zhanghuan
 * @date: 2022/3/29 10:45
 * @description: create it
 */
@Controller
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private UserService userService;

    @Autowired
    private GoodsService goodsService;

    /**
     * 功能描述：跳转到商品列表页
     *
     * @param
     * @param model
     * @param user
     * @return
     */
    @RequestMapping("/toList")
    public String toList(Model model, User user) {

        model.addAttribute("user", user);
        List<GoodsVo> goodsVos = goodsService.findGoodsVo();
        model.addAttribute("goodsList", goodsVos);
        return "goodsList";
    }

    /**
     * 跳转商品详情页面
     *
     * @param goodsId
     * @return
     */
    @RequestMapping("/toDetail/{goodsId}")
    public String toDetail(Model model, User user, @PathVariable Long goodsId) {
        model.addAttribute("user", user);
        model.addAttribute("goods", goodsService.findGoodsVoByGoodsId(goodsId));
        return "goodsDetail";
    }
}
